package com.secxiot.provider.system.controller;

import com.secxiot.provider.SystemApi;
import com.secxiot.provider.system.dto.AppBannerDto;
import com.secxiot.provider.system.dto.AppNewsDto;
import com.secxiot.provider.system.dto.AppVersionDto;
import com.secxiot.provider.system.dto.FileLogDto;
import com.secxiot.provider.system.entity.AppRecommend;
import com.secxiot.provider.system.entity.FileLog;
import com.secxiot.provider.system.service.SystemService;
import com.secxiot.provider.system.vo.AppRegimeVo;
import com.secxiot.provider.system.vo.DataDictVo;
import com.secxiot.provider.system.vo.FileLogVo;
import com.secxiot.provider.system.vo.FilesStorageVo;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("system")
@RestController
public class SystemController implements SystemApi {

    @Autowired
    private SystemService systemService;

    //获取字典表数据
    @GetMapping("/dataDict")
    @Override
    public List<DataDictVo> listDataDict(@RequestParam(value = "parentCode", required = false) String parentCode) {
        return systemService.listDataDict(parentCode);
    }

    @PostMapping("filelog")
    @Override
    public Long saveFileLog(@RequestBody FileLog fileLog) {
        return systemService.saveFileLog(fileLog);
    }

    @GetMapping("filelog")
    @Override
    public FileLogDto getFileUri(Long logId) {
        return systemService.getFileUri(logId);
    }

    @PostMapping("/filelog/use")
    @Override
    public Long useFileLogs(@RequestParam List<Long> logIds) {
        return systemService.useFileLogs(logIds);
    }

    @PostMapping("/filelog/fileLogByCode")
    @Override
    public List<FileLogVo> selectFileByCode(@RequestParam String code) {
        return systemService.selectFileByCode(code);
    }

    @Override
    public AppVersionDto getAppVersion(String platform, String clientType) {
        return systemService.getAppVersion(platform, clientType);
    }

    @Override
    public List<AppBannerDto> getAppBanner(Long userId, Long hospitalId) {
        return systemService.getAppBanner(userId, hospitalId);
    }

    @Override
    public List<AppNewsDto> getAppNews(Long userId, Long hospitalId) {
        return systemService.getAppNews(userId, hospitalId);
    }

    @Override
    public List<AppRecommend> getAppRecommends(Long userId, Long hospitalId, Long pageNo, Long pageSize) {
        return systemService.getAppRecommends(userId, hospitalId, pageNo * pageSize, pageSize);
    }

    @Override
    public AppRecommend getAppRecommendById(Long recommendById) {
        return systemService.getAppRecommendById(recommendById);
    }

    /**
     * 资料库--列表
     *
     * @param userId     用户ID
     * @param hospitalId 医疗机构ID
     * @param pageNo     页数
     * @param pageSize   条数
     * @param isPage     是否分页  0 否  1 是
     * @param searchName 关键字
     * @return
     */
    @ApiOperation(value = "资料库--列表", httpMethod = "GET")
    @GetMapping("/filesStorage/list")
    @Override
    public List<FilesStorageVo> selectFilesStorage(Long userId, Long hospitalId, Integer pageNo, Integer pageSize, Integer isPage, String searchName) {
        return systemService.selectFilesStorage(userId, hospitalId, pageNo, pageSize, isPage, searchName);
    }

    /**
     * 资料库--详情
     *
     * @param id 资料库ID
     * @return
     */
    @ApiOperation(value = "资料库--详情", httpMethod = "GET")
    @GetMapping("/filesStorage/detail")
    @Override
    public FilesStorageVo getFilesStorageById(@RequestParam("id") Long id) {
        return systemService.getFilesStorageById(id);
    }

    /**
     * 资料库--添加
     *
     * @param filesStorageVo
     * @return
     */
    @ApiOperation(value = "资料库--添加", httpMethod = "POST")
    @PostMapping("/filesStorage/save")
    @Override
    public Long insertFilesStorage(@RequestBody FilesStorageVo filesStorageVo) {
        return systemService.insertFilesStorage(filesStorageVo);
    }


    /**
     * 资料库--修改
     *
     * @param filesStorageVo
     * @return
     */
    @ApiOperation(value = "资料库--修改", httpMethod = "POST")
    @PostMapping("/filesStorage/update")
    @Override
    public Long updateFilesStorage(@RequestBody FilesStorageVo filesStorageVo) {
        return systemService.updateFilesStorage(filesStorageVo);
    }

    /********************************医院文化制度***************************************/

    /**
     * 医院文化制度--列表
     *
     * @param type       数据字典 00015
     * @param hospitalId 医疗机构ID
     * @param pageNo     页数
     * @param pageSize   条数
     * @param isPage     是否分页  0 否  1 是
     * @param searchName 关键字
     * @return
     */
    @ApiOperation(value = "医院文化制度--列表", httpMethod = "GET")
    @GetMapping("/appRegime/list")
    @Override
    public List<AppRegimeVo> selectAppRegime(String type, Long hospitalId, Integer pageNo, Integer pageSize, Integer isPage, String searchName) {
        return systemService.selectAppRegime(type, hospitalId, pageNo, pageSize, isPage, searchName);
    }

    /**
     * 医院文化制度--详情
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "医院文化制度--详情", httpMethod = "GET")
    @GetMapping("/appRegime/detail")
    @Override
    public AppRegimeVo getAppRegimeById(@RequestParam("id") Long id) {
        return systemService.getAppRegimeById(id);
    }

    /**
     * 删除文件
     *
     * @param fileId
     * @return
     */
    @ApiOperation(value = "删除文件", httpMethod = "GET")
    @GetMapping("/deleteFile")
    @Override
    public int deleteFile(@RequestParam("fileId") Long fileId) {
        return systemService.deleteFile(fileId);
    }
}
